package com.ufo.dis.service.service.impl;

import com.ufo.dis.service.entity.HdfsDAO;
import com.ufo.dis.service.service.HdfsService;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.mapred.JobConf;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;

@Service("hdfsService")
public class HdfsServiceImpl implements HdfsService {
    JobConf conf = HdfsDAO.config();
    HdfsDAO hdfs = new HdfsDAO(conf);

    // 某个文件夹的文件列表
    @Override
    public FileStatus[] ls(String folder) throws IOException {
        FileStatus[] list = hdfs.ls("/" + folder);
        return list;
    }

    @Override
    public boolean mkdirs(String nn) {
        boolean a = false;
        try {
            hdfs.mkdirs(nn);
            a = true;
        } catch (IOException e) {
            e.printStackTrace();

        }
        return a;
    }

    @Override
    public boolean delete(String path) {

        boolean a = false;
        try {
            hdfs.rmr(path);
            a = true;
        } catch (IOException e) {
            e.printStackTrace();

        }
        return a;
    }

    @Override
    public boolean upload1(String path, String filepath) {
        boolean a = false;
        try {
            hdfs.upload1(filepath,path);
            a = true;
        } catch (IOException e) {
            e.printStackTrace();

        }
        return a;
    }

    @Override
    public void upload2(String fileName, InputStream in) throws InterruptedException, IOException, URISyntaxException {
       hdfs.upload2(fileName,in);

    }

    @Override
    public void upload3(String source, String dest) throws InterruptedException, IOException, URISyntaxException {
        hdfs.upload3(source,dest);
    }

    @Override
    public boolean mv(String path, String newpath) throws IOException {
        return hdfs.mv(path,newpath);
    }


}
